Page({
  data: {
    loading: false,
    userInfo: {
      name: '张三',
      gender: '男',
      age: 22,
      height: 178,
      weight: 70,
      bloodType: 'A',
      allergies: ['青霉素', '花粉'],
      chronicDiseases: ['无']
    },
    healthData: {
      bmi: 22.1,
      bmiStatus: '正常',
      bloodPressure: {
        systolic: 120,
        diastolic: 80,
        status: '正常'
      },
      bloodSugar: {
        value: 5.2,
        status: '正常'
      },
      heartRate: {
        value: 75,
        status: '正常'
      }
    },
    medicalHistory: [
      {
        id: 1,
        date: '2024-12-15',
        hospital: '第一附属医院',
        department: '内科',
        doctor: '王医生',
        diagnosis: '急性上呼吸道感染',
        treatment: '抗生素治疗，对症处理'
      },
      {
        id: 2,
        date: '2024-10-08',
        hospital: '第一附属医院',
        department: '骨科',
        doctor: '李医生',
        diagnosis: '踝关节扭伤',
        treatment: '消肿止痛，固定处理'
      },
      {
        id: 3,
        date: '2024-06-21',
        hospital: '第二附属医院',
        department: '消化内科',
        doctor: '张医生',
        diagnosis: '急性胃炎',
        treatment: '药物治疗，调整饮食'
      }
    ],
    showMedicalHistoryDetail: false,
    currentMedicalHistory: null
  },

  onLoad() {
    wx.setNavigationBarTitle({
      title: '健康档案'
    })
    
    // 模拟加载
    this.setData({ loading: true })
    setTimeout(() => {
      this.setData({ loading: false })
    }, 800)
  },
  
  // 查看病史详情
  viewMedicalHistoryDetail(e) {
    const id = e.currentTarget.dataset.id
    const medicalHistory = this.data.medicalHistory.find(item => item.id === id)
    
    if (medicalHistory) {
      this.setData({
        currentMedicalHistory: medicalHistory,
        showMedicalHistoryDetail: true
      })
    }
  },
  
  // 关闭病史详情
  closeMedicalHistoryDetail() {
    this.setData({
      showMedicalHistoryDetail: false
    })
  },
  
  // 下拉刷新
  onPullDownRefresh() {
    this.setData({ loading: true })
    setTimeout(() => {
      this.setData({ loading: false })
      wx.stopPullDownRefresh()
    }, 800)
  }
}) 